package com.webdemo10.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.webdemo10.pojo.User;
import com.webdemo10.service.UserService;
@Controller
@Namespace("/ssh/jsp")
@Action(value="updateUser",results={
		@Result(location="/WEB-INF/jsp/update.jsp"),
		@Result(location="queryUser",type="redirectAction",name="update")})
public class UpdateUser extends ActionSupport {

	private static final long serialVersionUID = 1L;
	@Autowired
	private UserService userService;
	private String flag;
	private int id;
	private User user;
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getFlag() {
		return flag;
	}
	public void setFlag(String flag) {
		this.flag = flag;
	}
	@Override
	public String execute() throws Exception {
		if("update".equals(flag)){
			userService.updateUser(user);
			return "update";
		}else{
			User user = userService.getUser(id);
			ActionContext.getContext().put("user", user);
			return SUCCESS;
		}
	}
}
